editingInfo = false;

function info_toggle(){
	editingInfo = !editingInfo;
	if(editingInfo){
		document.getElementById('info_regform').style.display = 'none';
		document.getElementById('info_editform').style.display = 'block';
		editingInfo = !editingInfo;
	}else{
		document.getElementById('info_regform').style.display = 'block';
		document.getElementById('info_editform').style.display = 'none';
	}
	openInfo();
}

function showPopup(type, key, sender)
{
	if (type == 'image')
	{
		TINY.box.show({image: "/downloadfile?key=" + key, openjs:function(){openImage()},boxid:'popupImageDiv'});
	}
	else if (type == 'video')
	{
		TINY.box.show({width:100, height:100, html: "<div id='boxVidDiv'><img id='videoLoadingImg' src='images/ajax-loader.gif' /><video onloadedmetadata='openVideo()' style='visibility:hidden' id='currentVideo' controls='controls'><source src='/downloadfile?key="+key +"' /></video></div>"})
		
	}
	else if (type == 'audio')
	{
		var index = $(sender).parent().parent()[0].rowIndex - 1;
		setSong(state.offset + index, state.listP, state.sort, state.desc);
	}
	else if (type == "edit")
	{
		TINY.box.show({url: "/info.jsp?key=" + key, width:400, openjs:function(){openInfo()}});
	}

}

function openInfo()
{

	var info = $('#info_content');
	TINY.box.size(info.outerWidth(), info.outerHeight()+10, true, true);
}

function editSubmit()
{
	var form = $('#editForm');
	$.post(form.attr('action'), form.serialize(), function(){loadTable()});
	TINY.box.hide();
	return false;
}

function openImage(){
	var image = $('#popupImageDiv').find('img');
	var width = image[0].naturalWidth;
	var height = image[0].naturalHeight;
	var ratio1 = height/width;
	var ratio2 = width/height;
	if (width > $(window).width() )
	{
		width = $(window).width();
		height = ratio1 * width;
	}
	if (height > $(window).height())
	{
		height = $(window).height();
		width = ratio2 * height;
	}

	image.width(width);
	image.height(height);
	TINY.box.size(width,height, false, true);

}

function openVideo()
{
	var video = document.getElementById('currentVideo');
			var width = video.videoWidth;
			var height = video.videoHeight;
			var ratio1 = height/width;
			var ratio2 = width/height;
			if (width > $(window).width() )
			{
				width = $(window).width();
				height = ratio1 * width;
			}
			if (height > $(window).height())
			{
				height = $(window).height();
				width = ratio2 * height;
			}
			$('#videoLoadingImg').attr('style', "display:none");
			$('#currentVideo').removeAttr('style');
			$('#currentVideo').width(width);
			$('#currentVideo').height(height);
			TINY.box.size(width,height, true, true);

}
